package com.fjl.filewriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

public class handFileTest
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
//		writeFileTest();
		deleteFiles();

	}
	
	public static void writeFileTest() 
	{
		String filePath = "D:/fjl/fjl.txt";
		File file = new File(filePath);
			
		try
		{
			if(!file.getParentFile().exists())
			{
				file.getParentFile().mkdirs();
			}
			
			boolean b = file.getParentFile().isDirectory();
			boolean c = file.getParentFile().isFile();
			
			FileOutputStream fOutputStream = new FileOutputStream(file);
			fOutputStream.write(filePath.getBytes());
			fOutputStream.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		
		
	}
	
	public static void deleteFiles()
	{
		String filePath = "D:/fjl";
		File file = new File(filePath);
		File[] files = file.listFiles();
		for(File f:files)
		{
			f.delete();
		}
		file.delete();
		file.deleteOnExit();
	}
	

	public static void fileWriterTest()
	{

		File file = new File("D:/HandleFileTest.txt");
		// FileOperation fileOperation = new FileOperation(file);
		try
		{
			if (!file.exists())
			{
				file.createNewFile();
			}
			// fileOperation.write2file("test");
			// byte[] bytes =
			// fileOperation.readFileToBytes("D:/HandleFileTest.txt");
			// fileOperation.writeBytesFile(bytes, "E:/HandleFileTest.txt");
			FileWriter filewrt = new FileWriter(file, true);
			filewrt.append("test1" + "\r\n");
			filewrt.flush();
			filewrt.close();
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
